@extends('layout.master')

@section('title','修改贴子')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')
    @if (session('message'))
        <div>
            <input type="hidden" id="hidden" name="hidden" value="hidden">
            <input type="hidden" id="message" name="message" value="{{ session('message') }}">
            <input type="hidden" id="status" name="status" value="{{ session('status') }}">
        </div>
    @endif
    <div class="white-box">
        <form class="form-horizontal form-material" method="post" id='formid' enctype="multipart/form-data">
	
			<div class="row">	
                <div class="col-md-2 col-sm-4">
                    <label class="control-label">所属圈子</label>
                    <div class="example">
                        <select id="circle_id" name="circle_id">
							@foreach(DB::table('kl_circle_dic')->select('id', 'name')->where('is_del','1')->get() as $value)
                                <option value="{{ $value->id}}" @if(intval($advice->circle_id) === intval($value->id)) selected @endif>{{ $value->name }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="col-md-2 col-sm-4">
                    <label class="control-label">发布用户名</label>
                    <div class="example">
                        <select id="user_id" name="user_id">
							@foreach(App\User::PostingsUsers() as $value)
                                <option value="{{ $value->c_id}}" @if(intval($advice->user_id) === intval($value->c_id)) selected @endif>{{ $value->name }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
				
			</div>
			<div class="row">			


                <div class="col-md-2 col-sm-4">
                    <label class="control-label">是否加精</label>
                    <div class="example">
                        <select id="is_excellent" name="is_excellent">
                            @foreach(App\Carticle::$IsexcDisplay as $key => $value)
                                <option value="{{ $key }}" @if(intval($advice->is_excellent) === intval($key)) selected @endif >{{ $value }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
				
			</div>	

            <div class="row">
                <div class="col-lg-2 col-md-2">
                    <div class="row">
                        <label class="control-label">图片/视频</label>
                    </div>
                    <div class="row">
                        <div class="radio radio-purple">
                            <input type="radio" name="porm" @if(!empty($cover[0]->pic_path)) checked disabled @endif id="pic" value="1">
                            <label for="radio8"> 图片 </label>
                        </div>
                    </div>
                    <div class="row">
                        <div class="radio radio-purple">
                            <input type="radio" name="porm" @if(!empty($advice->video)) checked disabled @endif id="video" value="2">
                            <label for="radio8"> 视频 </label>
                        </div>
                    </div>
                </div>
                <div align="center" class="col-md-10 col-lg-10">
                    @if(!empty($advice->video))
            
                        <div class="col-lg-4 col-md-4" id="video">
						<label class="control-label">如果您想更换视频，请在这里选择新的视频</label>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="video"
                                       data-height="100px"
                                       data-default-file=""/>
                            </div>
							<video controls style="width: 50%;height:99%;">
								<source src="{{ $advice->video }}" type="video/mp4">
								<source src="{{ $advice->video }}" type="video/ogg">
								<source src="{{ $advice->video }}" type="video/webm">
								<object data="{{ $advice->video }}">
									<embed src="{{ $advice->video }}">
								</object>
							</video>
                        </div>
                    @elseif(!empty($cover[0]->pic_path))
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[1]))onclick="picdel({{ $cover[0]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic0"
                                       data-height="100px"
                                       data-default-file="{{ $cover[0]->pic_path }}"/>
                            </div>
                        </div>
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[1]))onclick="picdel({{ $cover[1]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic1"
                                       data-height="100px"
                                       data-default-file="@if(isset($cover[1])){{ $cover[1]->pic_path }}@endif"/>
                            </div>
                        </div>
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[2]))onclick="picdel({{ $cover[2]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic2"
                                       data-height="100px"
                                       data-default-file="@if(isset($cover[2])){{ $cover[2]->pic_path }}@endif"/>
                            </div>
                        </div>
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[3]))onclick="picdel({{ $cover[3]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic3"
                                       data-height="100px"
                                       data-default-file="@if(isset($cover[3])){{ $cover[3]->pic_path }}@endif"/>
                            </div>
                        </div>
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[4]))onclick="picdel({{ $cover[4]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic4"
                                       data-height="100px"
                                       data-default-file="@if(isset($cover[4])){{ $cover[4]->pic_path }}@endif"/>
                            </div>
                        </div>
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[5]))onclick="picdel({{ $cover[5]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic5"
                                       data-height="100px"
                                       data-default-file="@if(isset($cover[5])){{ $cover[5]->pic_path }}@endif"/>
                            </div>
                        </div>
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[6]))onclick="picdel({{ $cover[6]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic6"
                                       data-height="100px"
                                       data-default-file="@if(isset($cover[6])){{ $cover[6]->pic_path }}@endif"/>
                            </div>
                        </div>
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[7]))onclick="picdel({{ $cover[7]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic7"
                                       data-height="100px"
                                       data-default-file="@if(isset($cover[7])){{ $cover[7]->pic_path }}@endif"/>
                            </div>
                        </div>
                        <div class="col-lg-4 col-md-4">
                            <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                               @if(isset($cover[8]))onclick="picdel({{ $cover[8]->id }})"@endif>删除此图</a>
                            <div class="form-group ">
                                <input type="file" id="input-file-now-custom-3" class="dropify" name="pic8"
                                       data-height="100px"
                                       data-default-file="@if(isset($cover[8])){{ $cover[8]->pic_path }}@endif"/>
                            </div>
                        </div>
                    @endif
                </div>
            </div>

            <div class="row">
				<div class="form-group m-b-40 m-t-10">
					<p for="remarks">内容</p>
					<textarea id="content" name="content" cols="80" rows="5">{{ $advice->content }}</textarea>
				</div>
            </div>

        
        <div class="form-group">
            <button type="button" class="fcbtn btn btn-success btn-outline btn-1e waves-effect" id="publish">修改
            </button>

            {!! csrf_field() !!}
            <a class="fcbtn btn btn-info btn-outline btn-1e waves-effect" href="{{ url('/quanzi/list') }}">返回
            </a>
        </div>
	</form>
    </div>

@endsection
@section('js')
    @parent
    <script>
        $(document).ready(function () {
            $('#summernote').summernote();
        });
        $('#summernote').summernote({
            height: 500,
            toolbar: [
                // [groupName, [list of button]]
                ['style', ['bold', 'italic', 'underline', 'clear']],
                ['fontsize', ['fontsize']],
                ['fontname', ['fontname']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['height', ['height']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['fullscreen', 'codeview', 'help']]
            ],
            lang: 'zh-CN',
            placeholder: '内容',
            dialogsFade: true,
            callbacks: {
                onImageUpload: function (files) {
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        data: data,
                        type: "POST",
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: "/upload", /*填写后台上传文件的路径*/
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function (url) {/*url为上传成功后返回的图片路径*/
                            var imgNode = document.createElement('img');
                            imgNode.src = url;
                            $('#summernote').summernote('insertNode', imgNode);
                        }
                    })
                }
            }
        });
    </script>

    <script>
	        $(document).ready(function () {
            var hidden = $('#hidden').val();
            if (hidden === 'hidden') {
                if ($('#status').val() == 1) {
                    toastsuccess($('#message').val());
                } else {
                    toasterror($('#message').val());
                }
            }
        });
        $("#publish").click(function (e) {
			var content = $("#content").val();

			if(content==''){
				 swal("帖子内容不能为空!");
				 return false; 
			}
			var len = content.length; 
			if ( len < 5 ) {
				swal("帖子内容不能少为5个字符!");
				return false; 
			}
			document.getElementById("formid").submit();
        });
        function picdel(pic_id) {

            swal({
                    title: "",
                    text: "确定删除该图片吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/quanzi/listpicdel/' + pic_id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {

                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }
        $('#pic').click(function () {
            $('#file2').show();
            $('#file3').show();
            $('#file4').show();
            $('#file5').show();
            $('#file6').show();
            $('#file7').show();
            $('#file8').show();
            $('#file9').show();
        });

        $('#video').click(function () {
            $('#file2').hide();
            $('#file3').hide();
            $('#file4').hide();
            $('#file5').hide();
            $('#file6').hide();
            $('#file7').hide();
            $('#file8').hide();
            $('#file9').hide();
        });
    </script>
@endsection